#include "BigNumber_integer.h"
#include "test.h"
using namespace std;

typedef BigNumber_integer bint;

void test()
{
	for (int i = 1; i <= 30; ++i)
	{
		cout << "void test" << i << "();" << endl;
	}
}

int main()
{
	//test();
	//test1();
	//test2();
	//test3();
	//test7();
	//test4();
	//test5();
	//test6();
	//test8();
	//test9();
	//test10();
	//test11();
	//test12();
	//test13();
	//test14();
	//test15();
	//test16();
	//test17();
	//test18();
	//test19();
	//test20();
	//test21();

	return 0;
}

void test21()
{
	srand((unsigned int)time(NULL));

	int a = 0;
	int b = 0;
	bint c = 0;
	bint d = 0;
	int count = 0;
	bint bcount = 0;

	for (int i = 0; i < 30000; ++i)
	{
		int getSign = rand() % 2;
		int getSign2 = rand() % 2;
		a = rand() + 1;
		b = rand() + 1;
		if (getSign == 1)
		{
			a = -a;
		}
		if (getSign2 == 1)
		{
			b = -b;
		}
		c = a;
		d = b;
		if (c % d == a % b)
		{
			++count;
			++bcount;
		}
		else
		{
			cout << "a = " << a << " " << "b = " << b << endl;
			cout << "c = " << c << " " << "d = " << d << endl;
			cout << "a % b == " << a % b << endl;
			cout << "c % d == " << c % d << endl;
		}
	}
	cout << "count == " << count << endl;
	cout << "bcount == " << bcount << endl;
}

void test20()
{
	bint a = 9;
	bint b = -73;
	b %= a;
	int c = 9;
	int d = -73;
	d %= c;
	cout << d << endl;
	cout << b << endl;
}

void test19()
{
	//long long a = 134217728000000000000000;
	//long long b = 134217728000000000001342177280;
	bint a1 = "134217728000000000000000";
	bint b1 = "134217728000000000001342177280";
			 //999999999999999999999999999999
	cout << b1 / a1 << endl;
	cout << b1 / 0 << endl;
}

BigNumber_integer factorial(BigNumber_integer& bigNumber)
{
	bint sum = 1;
	for (bint i = 2; i <= bigNumber; ++i)
	{
		sum *= i;
	}
	return sum;
}

void test18()
{
	bint a = 0;
	while (cin >> a)
	{
		cout << factorial(a) << endl;
	}
}

void test17()
{
	bint a = -31860;
	bint b = 1770;
	bint c = -15668;
	bint d = 15668;
	cout << a / b << endl;
	cout << c / d << endl;
	//c = -31860 d = 1770
	//	c = -15668 d = 15668

	//bint a = 10;
	//bint b = -11;
	//bint c = -9;
	//bint d = 10;
	//c = 4809 d = -3
	//bint e = 4809;
	//bint f = -3;
	//cout << e / f << endl;

	//cout << b / a << endl;
	//cout << b / c << endl;
	//cout << a / d << endl;
	//cout << a / c << endl;
}

void test16()
{
	srand((unsigned int)time(NULL));

	int a = 0;
	int b = 0;
	bint c = 0;
	bint d = 0;
	int count = 0;
	bint bcount = 0;

	for (int i = 0; i < 20000; ++i)
	{
		int getSign = rand() % 2;
		int getSign2 = rand() % 2;
		a = rand() + 1;
		b = rand() + 1;
		if (getSign == 1)
		{
			a = -a;
		}
		if (getSign2 == 1)
		{
			b = -b;
		}
		c = a;
		d = b;
		if (c / d == a / b)
		{
			++count;
			++bcount;
		}
		else
		{
			cout << "a = " << a << " " << "b = " << b << endl;
			cout << "c = " << c << " " << "d = " << d << endl;
			cout << "a / b == " << a / b << endl;
			cout << "c / d == " << c / d << endl;
		}
	}
	cout << "count == " << count << endl;
	cout << "bcount == " << bcount << endl;
}

void test15()
{
	bint a = 1015;
	bint b = 15;

	a /= b;
	cout << a << endl;
}

void test14()
{
	bint a = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
	cout << 0 * a << endl;

}

void test13()
{
	srand((unsigned int)time(NULL));

	int a = 0;
	int b = 0;
	bint c = 0;
	bint d = 0;
	int count = 0;
	bint bcount = 0;

	for (int i = 0; i < 100000; ++i)
	{
		int getSign = rand() % 2;
		int getSign2 = rand() % 2;
		a = rand();
		b = rand();
		if (getSign == 1)
		{
			a = -a;
		}
		if (getSign2 == 1)
		{
			b = -b;
		}
		c = a;
		d = b;
		if (c * d == a * b)
		{
			++count;
			++bcount;
		}
		else
		{
			cout << "a = " << a << " " << "b = " << b << endl;
			cout << "c = " << c << " " << "d = " << d << endl;
			cout << "a * b == " << a * b << endl;
			cout << "c * d == " << c * d << endl;
		}
	}
	cout << "count == " << count << endl;
	cout << "bcount == " << bcount << endl;
}

void test12()
{
	bint a = 4742;
	bint b = -1694;
	cout << a * b << endl;
	//bint a = "9999999999999999999999";
	//bint b = "99999999999999999999999999999";
	//a *= b;
	////cout << a << endl;
	//bint c = 9;
	//bint d = -9;
	////cout << c * d << endl;

	////bint e = "-02";
	//bint e("-02", true);
	//bint i = "-0";
	//bint f = 10;
	////cout << e * f << endl;

	//bint g = 0;
	//bint h = -100;
	//cout << g * h << endl;

	//bint a = "-02";
	//bint b("-02", true);
	//bint c = { "-92389fdfeflkg3", true };

	//bint d = { "-9", true };

	//bint e = { "-000000000000", true };

	//cout << e << endl;

	//cout << d << endl;

	//cout << c << endl;

	//cout << a << " " << b << endl;
}

void test11()
{
	bint a = 10;
	a = a + a;
	cout << a << endl;
}

void test10()
{
	srand((unsigned int)time(NULL));

	int a = 0;
	int b = 0;
	bint c = 0;
	bint d = 0;
	int count = 0;
	bint bcount = 0;

	for (int i = 0; i < 100000; ++i)
	{
		int getSign = rand() % 2;
		int getSign2 = rand() % 2;
		a = rand();
		b = rand();
		if (getSign == 1)
		{
			a = -a;
		}
		if (getSign2 == 1)
		{
			b = -b;
		}
		c = a;
		d = b;
		if (c + d == a + b)
		{
			++count;
			++bcount;
		}
		else
		{
			cout << "a = " << a << " " << "b = " << b << endl;
			cout << "c = " << c << " " << "d = " << d << endl;
			cout << "a + b == " << a + b << endl;
			cout << "c + d == " << c + d << endl;
		}
		if (c - d == a - b)
		{
			++count;
			++bcount;
		}
		else
		{
			cout << "a = " << a << " " << "b = " << b << endl;
			cout << "c = " << c << " " << "d = " << d << endl;
			cout << "a - b == " << a - b << endl;
			cout << "c - d == " << c - d << endl;
		}

		//if ((c += d) == (a += b))
		//{
		//	++count;
		//	++bcount;
		//}
		//else
		//{
		//	cout << "a = " << a << " " << "b = " << b << endl;
		//	cout << "c = " << c << " " << "d = " << d << endl;
		//	cout << "a += b == " << a << endl;
		//	cout << "c += d == " << c << endl;
		//}
		//if ((c -= d) == (a -= b))
		//{
		//	++count;
		//	++bcount;
		//}
		//else
		//{
		//	cout << "a = " << a << " " << "b = " << b << endl;
		//	cout << "c = " << c << " " << "d = " << d << endl;
		//	cout << "a + b == " << a + b << endl;
		//	cout << "c + d == " << c + d << endl;
		//}
	}
	cout << "count == " << count << endl;
	cout << "bcount == " << bcount << endl;
}

void test9()
{
	bint sz = "100000000000000000100";
	bint in = "100000000000000000000";
	while (in < sz)
	{
		if (in == "10")
		{
			int i = 0;
		}
		cout << in << endl;
		++in;
	}
}

void test8()
{
	//int a = 1;
	//++(+a);
	////1++;
	//cout << a << endl;
	//bint b = 1;
	//(+b);
	//(+b)++;
}

void test6()
{
	bint a;
	bint b;
	char ch;
	while (true)
	{
		cin >> a >> ch >> b;
		if (ch == '+')
		{
			cout << a + b << endl;
		}
		else if (ch == '-')
		{
			cout << (a -= b) << endl;
		}
	}
}

void test5()
{
	bint a = -10;
	a += 9;
	cout << a << endl;

	bint b = -10;
	b += 9;
	cout << b << endl;

	bint c = 1;
	c += 9;
	cout << c << endl;

	bint d = 10;
	d += 9;
	cout << d << endl;
}

int add(const int& a, const int& b)
{
	int* p1 = (int*)(&a);
	int* p2 = (int*)(&b);

	*p1 = 3;
	*p2 = 6;
	return a + b;
}

void test7()
{
	int ret = add(1, 2);
	cout << ret << endl;
}

void test4()
{
	bint a = -7;
	bint b = -5;
	cout << a - b << endl;

	bint c = 7;
	bint d = 5;
	cout << c - d << endl;

	bint e = -3;
	bint f = 3;
	cout << e - b << endl;
	cout << f - d << endl;

	cout << e - b << endl;
}

void test3()
{
	bint c = -9838;
	bint a = c + (-9);
	cout << a << endl;
}

void test2()
{
	bint a = -1987928572958273984;
	int b = 9285;
	bint c = 1 + a;
	std::cout << (a += 1) << std::endl;
	//std::cout << b + 123 << std::endl;
}

void test1()
{
	//bint a = "123";
	//std::string* a = new std::string("1234");
	//std::string b = *a;

	//delete a;
	float b = -9.12324f;
	bint a = b;
	double c = -349809231.2983443;
	bint d = c;
	bint e = -1;
	e += a;

	bint f = bint(e);
	bint h = bint::to_bigNum_int(f);
	std::cout << e << std::endl;
	std::cout << d;
	int i = 0;
}